package org.example.rowing.vo;

import lombok.Data;
import org.example.rowing.domain.Race;
import org.example.rowing.domain.Team;

import java.util.Objects;

@Data
public class RoundScoreVO {
    private Long raceId;
    private RegistrationVO registrationVO;
    private String round;

    private String labelId;
    private String lane;
    private Double score;
    private Integer rank;
    private String status; // 取值为DNS/DNF/DSQ/NORMAL

    // 仅用作查询条件
    private Long registrationId;
    private Long eventId;

    public RoundScoreVO() {}

    public RoundScoreVO(Long raceId, RegistrationVO registrationVO, String round, String labelId, String lane, Double score) {
        this.raceId = raceId;
        this.registrationVO = registrationVO;
        this.round = round;
        this.labelId = labelId;
        this.lane = lane;
        this.score = score;
        this.status = "NORMAL";
    }

    public RoundScoreVO(Long raceId, RegistrationVO registrationVO, String round, String labelId, String lane, Double score, String status) {
        this.raceId = raceId;
        this.registrationVO = registrationVO;
        this.round = round;
        this.labelId = labelId;
        this.lane = lane;
        this.score = score;
        this.status = status;
    }

    @Override
    public int hashCode() {
        if (registrationVO == null || registrationVO.getRegistrationId() == null) {
            return -1;
        }
        int result = 17;
        int id = registrationVO.getRegistrationId().intValue();
        result = result + id;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        RoundScoreVO roundScoreVO = (RoundScoreVO) obj;
        if (registrationVO == null || roundScoreVO.getRegistrationVO() == null || registrationVO.getRegistrationId() == null || roundScoreVO.getRegistrationVO().getRegistrationId() == null)
            return false;
        return Objects.equals(roundScoreVO.getRegistrationVO().getRegistrationId(), registrationVO.getRegistrationId());
    }
}
